function compose(...fns) {
  if (fns.length <= 0) {
    return (x)=>x
  }
  
  return function (val) {
    let resVal = val
    for (let i = 0; i < fns.length; i++) {
      resVal = fns[i](resVal)
    }
    return resVal
  }
}

function fn1(x) {
  return x + 1;
}
function fn2(x) {
  return x + 2;
}
function fn3(x) {
  return x + 3;
}
function fn4(x) {
  return x + 4;
}

const a = compose(fn1);
console.log(a(1)); // 1+4+3+2+1=11